import Vue from 'vue'
import Vuex from 'vuex'
import { createLogger } from 'vuex'
import axios from "axios"
Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createLogger()],
  state: {
    list: [
      {
        id: "1",
        name: "张三",
        tel: "13000000000",
        address: "浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室",
        isDefault: true,
      },
      {
        id: "2",
        name: "李四",
        tel: "1310000000",
        address: "浙江省杭州市拱墅区莫干山路 50 号",
      },
    ],
    arr:[],
    disabledList: [
      {
        id: "3",
        name: "王五",
        tel: "1320000000",
        address: "浙江省杭州市滨江区江南大道 15 号",
      },
    ],
  },
  getters: {
  },
  mutations: {
    address(state,payload){   // 新增地址的方法
        console.log(payload)
        state.list.push(payload)
        
    },
    editaDDRESS(state,payload){  // 编辑地址得方法
        console.log(payload);
        state.list[payload.index] =payload
    },
    deleleitem(state,payload) {  // 删除地址得方法
        state.list.splice(payload,1)
    },
    setArr(state,payload) {
        state.arr = payload
    },
    setAddarr(state,payload){  // 上拉加载往数据里追加得
        let arr = [...state.arr,...payload]
        state.arr = arr
    } 

  },
  actions: {  // atcion里放异步的方法
       getList({commit}) {
          axios.get("/getlist").then(res=>{
              commit("setArr",res.data)
          })
       },
       getAddList({commit}){
            axios.get("/addlist").then(res=>{
              commit("setAddarr",res.data)
            })
       }
  },
  modules: {
  }
})
